import { defineStore } from "pinia";

import { ref } from "vue";
import {
  getSystemProperties,
  getSystemPropertiesBatch,
} from "@/api/system/properties/properties";
export const useSystemStore = defineStore("systemStore ", {
  state: () => ({
    // 书本审核状态
    contributeJudgeDictionary: ref({
      20101: "待审核",
      20102: "审核通过",
      20103: "审核失败",
    }),
    // 评论审核状态
    commentJudgeDictionary: ref({}),
    // 固有成员，系统列表
    systemInitList: ["comment-judge-state", "contribute-judge-state"],
    isInit: false,
  }),

  actions: {
    /**
     * 初始化函数
     * @returns
     */
    async systemDictionaryInit() {
      // 初始化判断
      if (!this.isInit) {
        this.isInit = true;
      } else {
        return;
      }
      // 构造参数
      const query = {}; //new PropertiesBatchDto();
      query.keys = this.systemInitList;
      // 获取列表
      const systemList = await getSystemPropertiesBatch(query);
      console.log("systemList", systemList);
      // 赋值
      var systemMap = new Map();
      for (let i = 0; i < systemList.length; i++) {
        // 获取当前元素
        const item = systemList[i];
        console.log(item);
        systemMap.set(item.name, JSON.parse(item.value));
      }
      console.log("systemDict", systemMap);
      // 赋值给各个配置
      this.contributeJudgeDictionary = systemMap.get("contribute-judge-state");
      console.log("contributeJudgeDictionary", this.contributeJudgeDictionary);
      //commentJudgeDictionary
      this.commentJudgeDictionary = systemMap.get("comment-judge-state");
      console.log("commentJudgeDictionary", this.commentJudgeDictionary);
    },

    /**
     * 登录成功事件
     */
    async userLoginSuccess() {},
  },
});
